home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / print / SimpleDoc.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.0 KB  |  94 lines

  1. package javax.print;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.CharArrayReader;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.Reader;
  8. import java.io.StringReader;
  9. import javax.print.attribute.AttributeSetUtilities;
  10. import javax.print.attribute.DocAttributeSet;
  11.  
  12. public final class SimpleDoc implements Doc {
  13.    private DocFlavor flavor;
  14.    private DocAttributeSet attributes;
  15.    private Object printData;
  16.    private Reader reader;
  17.    private InputStream inStream;
  18.  
  19.    public SimpleDoc(Object var1, DocFlavor var2, DocAttributeSet var3) {
  20.       if (var2 != null && var1 != null) {
  21.          Object var4 = null;
  22.  
  23.          try {
  24.             var7 = Class.forName(var2.getRepresentationClassName());
  25.          } catch (Throwable var6) {
  26.             throw new IllegalArgumentException("unknown representation class");
  27.          }
  28.  
  29.          if (!var7.isInstance(var1)) {
  30.             throw new IllegalArgumentException("data is not of declared type");
  31.          } else {
  32.             this.flavor = var2;
  33.             if (var3 != null) {
  34.                this.attributes = AttributeSetUtilities.unmodifiableView(var3);
  35.             }
  36.  
  37.             this.printData = var1;
  38.          }
  39.       } else {
  40.          throw new IllegalArgumentException("null argument(s)");
  41.       }
  42.    }
  43.  
  44.    public DocFlavor getDocFlavor() {
  45.       return this.flavor;
  46.    }
  47.  
  48.    public DocAttributeSet getAttributes() {
  49.       return this.attributes;
  50.    }
  51.  
  52.    public Object getPrintData() throws IOException {
  53.       return this.printData;
  54.    }
  55.  
  56.    public Reader getReaderForText() throws IOException {
  57.       if (this.printData instanceof Reader) {
  58.          return (Reader)this.printData;
  59.       } else {
  60.          synchronized(this) {
  61.             if (this.reader != null) {
  62.                return this.reader;
  63.             }
  64.  
  65.             if (this.printData instanceof char[]) {
  66.                this.reader = new CharArrayReader((char[])this.printData);
  67.             } else if (this.printData instanceof String) {
  68.                this.reader = new StringReader((String)this.printData);
  69.             }
  70.          }
  71.  
  72.          return this.reader;
  73.       }
  74.    }
  75.  
  76.    public InputStream getStreamForBytes() throws IOException {
  77.       if (this.printData instanceof InputStream) {
  78.          return (InputStream)this.printData;
  79.       } else {
  80.          synchronized(this) {
  81.             if (this.inStream != null) {
  82.                return this.inStream;
  83.             }
  84.  
  85.             if (this.printData instanceof byte[]) {
  86.                this.inStream = new ByteArrayInputStream((byte[])this.printData);
  87.             }
  88.          }
  89.  
  90.          return this.inStream;
  91.       }
  92.    }
  93. }
  94.